package org.codefinger.dao.impl.sql.ast;

import org.codefinger.dao.impl.SQLVisitor;
import org.codefinger.dao.impl.sql.Expression;

public class BetweenExpression implements Expression {

	private Expression	exp;

	private Expression	between;

	private Expression	and;

	public BetweenExpression(Expression and, Expression between, Expression exp) {
		super();
		this.exp = exp;
		this.between = between;
		this.and = and;
	}

	@Override
	public boolean matchVisit(SQLVisitor visitor) {
		int sqlSize = visitor.getSqlSize();
		int paramSize = visitor.getParamSize();
		if (exp.matchVisit(visitor)) {
			visitor.appendSQL(" BETWEEN ");
			if (between.matchVisit(visitor)) {
				visitor.appendSQL(" AND ");
				if (and.matchVisit(visitor)) {
					return true;
				}
			}
		}
		visitor.back(sqlSize, paramSize);
		return false;
	}

	@Override
	public void visit(SQLVisitor visitor) {
		exp.visit(visitor);
		visitor.appendSQL(" BETWEEN ");
		between.visit(visitor);
		visitor.appendSQL(" AND ");
		and.visit(visitor);
	}

}
